package com.kaifamiao.array;

import java.util.Arrays;

public class PandaTest3 {

	public static void main(String[] args) {
		
		Panda[] pandas = new Panda[ 5 ];
		System.out.println( Arrays.toString( pandas ) );
		
		pandas[ 0 ] = new Panda( "团团" , '男' , 25000 , 120 );
		pandas[ 1 ] = new Panda( "圆圆" , '女' , 30000 , 140 );
		pandas[ 2 ] = new Panda( "和和" , '男' , 24000 , 110 );
		pandas[ 3 ] = new Panda( "美美" , '女' , 32000 , 130 );
		pandas[ 4 ] = new Panda( "熊猫儿" , '男' , 20000 , 108 );
		
		System.out.println( Arrays.toString( pandas ) );
		
		for( int i = 0 , m = pandas.length - 1 ; i < m ; i++ ) {
			for( int j = 0 , n = m - i ; j < n ; j++ ) {
				// 若相邻的两个元素中前一个比后一个大
				if( pandas[j].compareTo( pandas[j+1] ) > 0 ) {
					Panda p = pandas[ j ] ;
					pandas[ j ] = pandas[ j + 1 ] ;
					pandas[ j + 1 ] = p ;
				}
			}
		}
		
		System.out.println( Arrays.toString( pandas ) );

	}

}
